package com.ssm.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.mapper.UserMapper;
import com.ssm.model.User;
import com.ssm.service.UserService;
import com.ssm.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author:随缘而愈
 * @date 27/10/2023 上午11:01
 * @description:必出BUG
 * @params
 * @return
*/
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public ResultData findAll() {

        PageHelper.startPage(1,5);

        List<User> all = userMapper.findAll();

        PageInfo<User> info = new PageInfo<>(all);
        long count = info.getTotal();
        int pageSize = info.getPageSize();
        int pages = info.getPages();

        return ResultData.ok(all,count,pageSize,pages);
    }

    @Override
    public List<User> findAll2() {
        return userMapper.findAll();
    }

    @Override
    @Transactional( noRollbackFor = Exception.class)
    public int update() {
        User user = new User();
        user.setId(1);
        user.setUserName("sss");
        userMapper.update(user);

        System.out.println(1/0);

        user.setUserName("ddd");
        userMapper.update(user);

        return 0;
    }


}
